$(function () {
    //抽取变量
    var history_datagrid = $("#history_datagrid");
    var query_dialog = $("#query_dialog");
    var query_form = $("#query_form");
    //初始化datagrid
    history_datagrid.datagrid({
        fit: true,
        fitColumns: true,
        striped: true,
        url: "/transferHistory/list.do",
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        toolbar: "#history_toolbar",
        columns: [[
            {
                field: 'client1', title: '学生姓名', width: 100, align: 'center', formatter: function (value, row, index) {
                    return row.client ? row.client.name : "";
                }
            },
            {
                field: 'client2', title: 'QQ', width: 100, align: 'center', formatter: function (value, row, index) {
                    return row.client ? row.client.qq : "";
                }
            },
            {
                field: 'client3', title: '联系电话', width: 100, align: 'center', formatter: function (value, row, index) {
                    return row.client ? row.client.tel : "";
                }
            },
            {field: 'transferDate', title: '日期', width: 100, align: 'center'},
            {field: 'oldSaleman', title: '原拥有者', width: 100, align: 'center'},
            {field: 'newSaleman', title: '移交目标', width: 100, align: 'center'}
        ]]
    });
    // 高级查询对话框
    query_dialog.dialog({
        width: 300,
        height: 250,
        title: '查询',
        buttons: "#query_btns",
        closed: true
    });
    var methodObject = {
        query: function () {
            query_form.form("clear");
            query_dialog.dialog("open");
        },
        submitForm: function () {
            query_form.form("submit", {
                url: '/transferHistory/list.do',
                success: function (data) {
                    data = $.parseJSON(data);
                    if (data) {
                        query_dialog.dialog("close");
                        history_datagrid.datagrid("loadData", data);
                    }
                }
            })
        },
        reload: function () {
            history_datagrid.datagrid("reload");
        },
        cancelQuery: function () {
            query_dialog.dialog("close");
        },
    };
    $("[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        methodObject[cmd]();
    })
});